#pragma once
#include <string>
#include <windows.h>
#include <vector>

class Profiler {

struct stopWatch {
     LARGE_INTEGER start;
     LARGE_INTEGER stop;
};

struct Profile {
	std::string name;
	Profile* parent;
	bool active;
	stopWatch timer;
	int calls;
	double elapsed;
	int level;
};

struct ProfileFrame {
    std::string name;
    int calls;
    double duration;
};

struct ProfileNode {
    ProfileNode* parent;
    std::vector<ProfileNode*> children;
    std::string name;
    LARGE_INTEGER started;
    double duration;
    double accu;
};

typedef std::vector<ProfileFrame> Frames;


//typedef std::vector<Profile*> Profiles;
//typedef std::vector<Profile*> ProfileHistory;

public:
	Profiler();
	~Profiler();
	void start(const std::string& name);
	void end(const std::string& name);
	 void print();
	 void debug();
	 void reset();
private:
	// methods
	double LIToSecs( LARGE_INTEGER & L);
	void printNodes(const std::vector<ProfileNode*>& nodes, int lvl,double total);
	void resetNodes(const std::vector<ProfileNode*>& nodes);
	float calculatePercentage(double current,double total);
	void debugNodes(const std::vector<ProfileNode*>& nodes, int lvl,double total,int y);
	std::string fillString(const std::string& txt,int length);
	//
	LARGE_INTEGER frequency;
	// new stuff
	Frames m_Frames;
    ProfileNode* m_Root;
    ProfileNode* m_Current;
};
/*
extern Profiler* gProfiler;

#define PR_START(a) gProfiler->start(a);
#define PR_END(a) gProfiler->end(a);
*/
